package com.txc.cloud.auth.service;

import cn.hutool.core.util.ObjectUtil;
import com.txc.cloud.auth.model.vo.CurrentUser;
import com.txc.openfeign.common.admin.api.UserClient;
import com.txc.common.global.model.LoginUser;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author TXC
 * @since 2022-08-02
 */
@Service
public class UserServiceImpl implements UserDetailsService {
    @Resource
    private UserClient userClient;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        LoginUser loginUser = userClient.getUserinfo(username);
        if (ObjectUtil.isNull(loginUser)) {
            throw new UsernameNotFoundException("用户不存在");
        }
        return new CurrentUser(loginUser);
    }


}
